<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
</head>
<link href="../../style/css/back/style.css" rel="stylesheet" type="text/css">
<script src="../../style/js/jquery-1.8.3.js"></script>
<script src="../../style/js/ajaxfileupload.js"></script>

<script type="text/javascript">
    $(function () {
//接收管理员id
        var id = location.search.split("=")[1];
        $("input[name='id']").val(id);
        $.get("../../webmsg/webmsg", {id: id}, function (res) {
            console.log(res.data)
            $("input[name='webName']").val(res.data.webName);
            $("input[name='companyName']").val(res.data.companyName);
            var str=""
            str+="<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/logo/" + res.data.logoName + "' width='200' height='90'/>"
            $("input[name='logoName']").html(str)
            $("input[name='phone']").val(res.data.phone);
            $("input[name='recordNum']").val(res.data.recordNum);
        });
    })

    function  save(){
        $.post("../../webmsg/savewebmsg",$("#formId").serialize(),function(res){
            if(res.code==202){
                window.parent.location.replace("list.html");
            }else if(res.code==500){
                alert("服务器忙,请稍后再试!");
            }else{
                alert("保存成功!");
                location.replace("list.html");
            }
        });
    }

    function fileupload(){
        $.ajaxFileUpload({
            url:'../../webmsg/logo', //用于文件上传的服务器端请求地址
            fileElementId:'fileid', //文件上传域的ID
            dataType: 'json', //返回值类型 一般设置为json
            success: function (data) {
                console.log(data);
                var filename=window.sessionStorage.setItem("filename",data.data.logoName);
                var id=window.sessionStorage.setItem("id",data.data.id);
                location.assign("index.html");
            }
        })
    }
</script>
<body>
<form id="formId">
    <input type="hidden" name="id">
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <li>
                <label>标题</label>
                <input name="webName" id="webName" type="text" class="dfinput"/>
            </li>
            <li>
                <label>公司名</label>
                <input name="companyName" id="companyName" type="text" class="dfinput"/>
            </li>
            <li>
                <input type="file" name="filename" accept=".jpg,.png" id="fileid">
                <input type="button" value="上传logo" onclick="fileupload()">

            </li>
            <li>
                <label>电话</label>
                <input name="phone" id="phone" type="text" class="dfinput"/>
            </li>
            <li>
                <label>备案号</label>
                <input name="recordNum" id="recordNum" type="text" class="dfinput"/>
            </li>
            <li>
                <input type="button" class="btn" value="确认保存" onclick="save()"/>
            </li>
        </ul>
    </div>
</form>
</body>

</html>
